<template>
  <el-cascader ref="cascaderRef" class="cascader" v-model="deviceTypeId" :options="treeList.tree" placeholder=" " :props="deviceProps"
    @change="handleChange" collapse-tags collapse-tags-tooltip clearable />
</template>

<script setup lang="ts">
import { getTreeData } from "@/http/device";
import { dptQueryDptNoPage } from "@/http/userManage"

let deviceTypeId = ref(' ') as any;

const props = defineProps({
  needAll: {
    type: Boolean,
    default: true,
  },
  // selectData: {
  //   type: String,
  //   default: '' as any
  // }
})
// watch(() => props.selectData, (newValue, oldValue) => {
//   deviceTypeId.value = newValue

// });

const deviceProps = {
  children: 'childList',
  label: 'name',
  multiple: true,
  expandTrigger: 'hover' as const
}
const assignValue = (data: any) => {
  deviceTypeId.value = data
}
const treeList = reactive({
  tree: [
    {
      area: 999,
      code: '',
      codePath: '',
      id: '1',
      idPath: '',
      level: 1,
      name: '生产部',
      parentId: '',
      childList: [
        {
          area: 999,
          code: '',
          codePath: '',
          id: '01',
          idPath: '',
          level: 2,
          name: '张三',
          parentId: '',
          childList: []
        },
        {
          area: 999,
          code: '',
          codePath: '',
          id: '02',
          idPath: '',
          level: 2,
          name: '李四',
          parentId: '',
          childList: []
        },
      ]
    },
    {
      area: 999,
      code: '',
      codePath: '',
      id: '2',
      idPath: '',
      level: 1,
      name: '商务部',
      parentId: '',
      childList: [
        {
          area: 999,
          code: '',
          codePath: '',
          id: '11',
          idPath: '',
          level: 2,
          name: '王五',
          parentId: '',
          childList: []
        },
        {
          area: 999,
          code: '',
          codePath: '',
          id: '12',
          idPath: '',
          level: 2,
          name: '李六',
          parentId: '',
          childList: []
        },
      ]
    },
  ] as Array<any>,//员工列表
})

const cascaderRef = ref<any>("");

const emit = defineEmits(['getUserList', 'getTreeList']);
//选中项改变时
const handleChange = (val: any) => {
  console.log('112',val);
  let nodeChildren = cascaderRef.value.getCheckedNodes();
  console.log('nodeChildren',nodeChildren);
  
emit('getUserList',val)
}

const getTreeList = () => {

}

getTreeList();

//清空
const empty = () => {
  deviceTypeId.value = " ";
}

//暴露方法,父组件才能调用
defineExpose({ empty, assignValue });
</script>

<style scoped lang="scss"></style>